package DFS;

import java.util.*;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-03-21
 * Time:10:32
 * Text：1863. 找出所有子集的异或总和再求和
 */
public class Text7 {
    List<List<Integer>> list;
    List<Integer> t1;
    void dfs(int[] nums,int i){
        if(i==nums.length){
            List<Integer> path2=new ArrayList<>(t1);
            list.add(path2);
            return;
        }
        //不要
        dfs(nums,i+1);

        //要
        t1.add(nums[i]);
        dfs(nums,i+1);
        t1.remove(t1.size()-1);
    }
    int Xor(List<Integer> t){
        int count=0;
        for(int i=0;i<t.size();i++) {
            count=count ^ t.get(i);
        }
        return count;
    }

    public int subsetXORSum(int[] nums) {
        list=new ArrayList<>();
        t1=new ArrayList<>();
        dfs(nums,0);
        int count=0;
        for(List x:list){
            count+=Xor(x);
        }
        return count;
    }
    public static void main(String[] args) {
        Text7 t1=new Text7();
        int[] array={1,2,3};
        t1.subsetXORSum(array);
    }
}
